package com.qingke.oms.command.shop;

import java.util.List;

import com.qingke.oms.command.ShopCommand;
import com.qingke.oms.pojo.Shop;
import com.qingke.oms.pojo.ShoppingCart;
import com.qingke.oms.pojo.ShoppingCartItem;
import com.qingke.oms.pojo.User;
import com.qingke.oms.util.OMSConsole;

public class ViewShoppingCartCommand extends ShopCommand {

	public ViewShoppingCartCommand(User user, Shop shop) {
		super(user, shop);
	}

	@Override
	public void execute() {
		dao.clear();
		ShoppingCart shoppingCart=dao.selectShoppingCartByCustomerAndShop(user, shop);
		if(shoppingCart==null){
			OMSConsole.println("you have never add goods to shopping cart.");
			OMSConsole.println("so please add goods to shopping cart first.");
			return ;
		}
//		Set<ShoppingCartItem> items=shoppingCart.getShoppingCartItems();
		List<ShoppingCartItem> items=dao.selectShoppingCartItemByShoppingCart(shoppingCart);
		if(items.size()==0){
			OMSConsole.println("your shopping cart is empty.");
			return ;
		}
		boolean isAllZero=true;
		for(ShoppingCartItem item:items){
			if(item.getQuantity()!=0){
				isAllZero=false;
				break;
			}
		}
		if(isAllZero){
			OMSConsole.println("your shopping cart is empty.");
			return ;
		}
		OMSConsole.println("-------your shopping cart-------");
		for(ShoppingCartItem i:items){
			if(i.getQuantity()!=0)
				OMSConsole.println("Goods [id]:"+i.getGoods().getId()+",[name]:"+i.getGoods().getName()+",[price]:"+i.getPrice()+",[quantity]:"+i.getQuantity());
		}
	}

}
